#include <functional>

class ScopeGuard
{
   private:
    typedef std::function<void()> destructor_type;

    destructor_type destructor_;
    bool dismissed_;

   public:
    ScopeGuard(destructor_type destructor) : destructor_(destructor), dismissed_(false) {}

    ~ScopeGuard()
    {
        if (!dismissed_)
        {
            destructor_();
        }
    }

    void dismiss()
    {
        dismissed_ = true;
    }

    ScopeGuard(ScopeGuard const &) = delete;
    ScopeGuard &operator=(ScopeGuard const &) = delete;
};